/** Bombs-Must-Detonate: Linker Parser Generator **/


%token PROVIDE REQUIRE
%token <string> IDENTIFIER 
%token <int> INTVAL
%token EQUALS
%token INT FLOAT STRING BOOL VOID
%token ENUMTYPE ENUM STRUCT ARRAY LIST FUNCTION
%token ANYTHING
%token REF
%token TEMPLATE
%token COLON COMMA ARROW
%token <string> CODE
%token LPAREN RPAREN

%start link
%type <Linkst.link_st> link

%%

link:   CODE          { [Linkst.LnkCode $1] }
      | provide link  { $1::$2 }
      | require link  { $1::$2 }

provide: PROVIDE IDENTIFIER EQUALS link_type { Linkst.LnkProvide ($2,$4) }
require: REQUIRE IDENTIFIER EQUALS link_type { Linkst.LnkRequire ($2,$4) }

link_type:   INT      { Linkst.LnkInt }
           | FLOAT    { Linkst.LnkFloat }
	   | STRING   { Linkst.LnkString }
	   | BOOL     { Linkst.LnkBool }
	   | VOID     { Linkst.LnkVoid }
	   | ANYTHING { Linkst.LnkAnything }
	   | TEMPLATE LPAREN IDENTIFIER RPAREN
                      { Linkst.LnkTemplate $3 }
	   | ENUMTYPE LPAREN IDENTIFIER COLON INTVAL RPAREN
                      { Linkst.LnkEnumType ($3,$5) }
	   | ENUM LPAREN IDENTIFIER COLON INTVAL RPAREN
                      { Linkst.LnkEnum ($3,$5) }
	   | STRUCT LPAREN IDENTIFIER COLON link_type_list RPAREN
                      { Linkst.LnkStruct ($3,$5) }
	   | ARRAY LPAREN link_type RPAREN
                      { Linkst.LnkArray $3 }
	   | LIST LPAREN link_type RPAREN
                      { Linkst.LnkList $3 }
	   | FUNCTION LPAREN link_type_list ARROW link_type RPAREN
                      { Linkst.LnkFunction ($3,$5) }
	   | REF LPAREN link_type RPAREN
                      { Linkst.LnkRef $3 }

link_type_list: link_type
                      { [$1] }
	   | link_type COMMA link_type_list
                      { $1::$3 }
